package com.atguigu.gmall.search.listener;

import com.atguigu.gmall.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SpuInfoListener {
    
    
    @Autowired
    private SearchService searchService;

    @RabbitListener(bindings = @QueueBinding(value = @Queue(value = "gamll.item.queue", durable = "true"),
        exchange = @Exchange(value = "gamll.item.exchange", ignoreDeclarationExceptions = "true",
            type = ExchangeTypes.TOPIC),
        key = {"item.insert"}))
    public void listenInsertBySpuId(Long spuId) {
        if (spuId == null) {
            return;
        }
        searchService.createIndex(spuId);
    }
}
